package com.caiyouxi.advertise.service.impl;

import com.caiyouxi.advertise.mapper.AdvertiseSlideMapper;
import com.caiyouxi.advertise.model.AdvertiseSlideBean;
import com.caiyouxi.advertise.service.AdvertiseSlideService;
import com.caiyouxi.common.bean.QueryParams;
import com.caiyouxi.common.bean.ResData;
import com.caiyouxi.common.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class AdvertiseSlideServiceImpl extends BaseService implements AdvertiseSlideService {
    @Autowired
    private AdvertiseSlideMapper advertiseSlideMapper;

    /**
     * 新增
     * */
    @Override
    public ResData add_slide(AdvertiseSlideBean bean) {
        return success(advertiseSlideMapper.add_slide(bean));
    }

    /**
     * 删除
     * */
    @Override
    public ResData delete_slide(AdvertiseSlideBean bean) {
        return success(advertiseSlideMapper.delete_slide(bean));
    }

    /**
     * 修改
     * */
    @Override
    public ResData update_slide(AdvertiseSlideBean bean) {
        return success(advertiseSlideMapper.update_slide(bean));
    }

    /**
     * 查找
     * */
    @Override
    public ResData get_advertise_slide(AdvertiseSlideBean bean) {
        Integer page_list = Integer.parseInt(redisService.get("sys.pagesize").toString());
        QueryParams queryParams = new QueryParams();
        if(bean.getPagesize() == null){
            bean.setPagesize(page_list);
            bean.setPage_size(page_list);
        }
        if(bean.getPages() == null){
            bean.setPages(0);
        }
        queryParams.setTotal(advertiseSlideMapper.get_advertise_count(bean));
        queryParams.setList(advertiseSlideMapper.get_advertise_slide(bean));
        queryParams.setPage_size(bean.getPages());
        queryParams.setPage_size(bean.getPagesize());
        return page_list(queryParams);
    }

    @Override
    public ResData update_statues(AdvertiseSlideBean bean) {
        return success(advertiseSlideMapper.update_statues(bean));
    }

    @Override
    public ResData get_slide_info(AdvertiseSlideBean bean) {
        return success(advertiseSlideMapper.get_slide_info(bean));
    }
}
